package com.huangsm.book.designmodel;


import java.awt.*;
import java.util.Vector;

/**
 * 具体的主题实现
 * <p>
 * 注意，它维护了观察者队列，提供了增加和删除观察者的方法，并通过其inform()
 * 通知观察者
 *
 * @author huang
 * @PACKAGE_NAME com.huangsm.book.designmodel
 * @PROJECT_NAME concurrence
 * @date 2019/2/15
 */
public class ConcreateSubject implements ISubject {
    Vector<IObserver> observers = new Vector<IObserver>();

    @Override
    public void attach(IObserver observer) {
        observers.addElement(observer);
    }

    @Override
    public void detach(IObserver observer) {
        observers.removeElement(observer);
    }

    @Override
    public void inform() {
        Event evt = new Event("1",2,"4");
        observers.forEach(ob->ob.update(evt));
    }
}
